****APPENDIX FIGURE F2****

cd "$main_dir/output/figures/appendix_f"

graph set window fontface "Palatino"

//--------------------------------------------------------
//Read in relevant data
//--------------------------------------------------------

clear
use "$data_dir/clean/harmonized_dataset.dta"

merge m:1 ccode survey_year yob using "$data_dir/raw/lifeexp_variables_data/growth_rate_mpd_var_exp.dta", nogen keepusing(total_growth_rate_obs wgrowth_rate_1)

gen sample = 1 if born_country!=0 & total_growth_rate_obs>=0.9*(age-1) & total_growth_rate_obs!=.

//--------------------------------------------------------
//Create Figure F2
//--------------------------------------------------------

gen age_period = ""
replace age_period = "15-20" if age>=15 & age<=20
replace age_period = "21-30" if age>=21 & age<=30
replace age_period = "31-40" if age>=31 & age<=40
replace age_period = "41-50" if age>=41 & age<=50
replace age_period = "51-60" if age>=51 & age<=60
replace age_period = "61-70" if age>=61 & age<=70
replace age_period = "71-80" if age>=71 & age<=80
replace age_period = "80+" if age>80 & age!=.

matrix coef1 = J(8, 1, .)
matrix coln coef1 = variance
matrix rown coef1 = "15-20" "21-30" "31-40" "41-50" "51-60" "61-70" "71-80" "80+"

summarize wgrowth_rate_1 if age_period == "15-20" & sample == 1 & trust_govt != .
scalar s2 = r(Var)
mat coef1[1,1] = sqrt(s2)

summarize wgrowth_rate_1 if age_period == "21-30" & sample == 1 & trust_govt != .
scalar s2 = r(Var)
mat coef1[2,1] = sqrt(s2)

summarize wgrowth_rate_1 if age_period == "31-40" & sample == 1 & trust_govt != .
scalar s2 = r(Var)
mat coef1[3,1] = sqrt(s2)

summarize wgrowth_rate_1 if age_period == "41-50" & sample == 1 & trust_govt != .
scalar s2 = r(Var)
mat coef1[4,1] = sqrt(s2)

summarize wgrowth_rate_1 if age_period == "51-60" & sample == 1 & trust_govt != .
scalar s2 = r(Var)
mat coef1[5,1] = sqrt(s2)

summarize wgrowth_rate_1 if age_period == "61-70" & sample == 1 & trust_govt != .
scalar s2 = r(Var)
mat coef1[6,1] = sqrt(s2)

summarize wgrowth_rate_1 if age_period == "71-80" & sample == 1 & trust_govt != .
scalar s2 = r(Var)
mat coef1[7,1] = sqrt(s2)

summarize wgrowth_rate_1 if age_period == "80+" & sample == 1 & trust_govt != .
scalar s2 = r(Var)
mat coef1[8,1] = sqrt(s2)

coefplot matrix(coef1[,1]), vertical graphregion(color(white)) bgcolor(white) xtitle("Age Group", margin(medsmall)) ytitle("Standard Deviation" "of Growth Experience", margin(medsmall)) mcolor(maroon) connect(1) lcolor(black) lwidth(medthick)
graph export "figure_f2.png", replace
